<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
<title>Introduction to GTK+</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="GUI, Introduction to GTK+, GTK+ library, C">
<meta name="description" content="Introduction to GTK+">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content">


<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>


<h1>Introduction to GTK+</h1>


<h2>About this tutorial</h2>

<p>
This is an introductory GTK+ programming tutorial. The tutorial is 
targeted for the C programming language. It has been created and 
tested on Linux. The GTK+ programming tutorial is suited for novice and 
intermediate programmers. 
</p>

<div class="center"> 
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
</div>


<h2>GTK+</h2>

<p>
The <b class="keyword">GTK+</b> is a library for creating graphical user 
interfaces. The library is created in C programming language. The GTK+ library 
is also called the GIMP Toolkit. Originally, the library was created
while developing the GIMP image manipulation program. Since then, the 
GTK+ became one of the most popular toolkits under Linux and BSD Unix. 
Today, most of the GUI software in the open source world is created 
in Qt or in GTK+. The GTK+ is an object oriented application 
programming interface. The object oriented system is created with the
Glib object system, which is a base for the GTK+ library. 
The <b class="keyword">GObject</b> also enables to 
create language bindings for various other programming languages. 
Language bindings exist for C++, Python, Perl, Java, 
C# and other programming languages. 
</p>

<p>
The GTK+ itself depends on the following libraries. 
</p>

<ul>
<li>Glib</li>
<li>Pango</li>
<li>ATK</li>
<li>GDK</li>
<li>GdkPixbuf</li>
<li>Cairo</li>
</ul>

<p>
The <b class="keyword">Glib</b> is a general purpose utility library. It 
provides various data types, string utilities, 
enables error reporting, message logging, working with threads and other 
useful programming features. The <b class="keyword">Pango</b> is a library 
which enables internationalization. The <b class="keyword">ATK</b> is the 
accessibility toolkit. This toolkit provides tools which help physically challenged
people work with computers. The <b class="keyword">GDK</b> is a wrapper 
around the low-level drawing and windowing functions provided by the underlying 
graphics system. On Linux, GDK lies between the X Server and the GTK+ library. 
Recently, much of it's functionality have been delegated to the Cairo library. 
The <b class="keyword">GdkPixbuf</b> library is a toolkit for image loading and 
pixel buffer manipulation. <b class="keyword">Cairo</b> is a library for 
creating 2D vector graphics.
It has been included in GTK+ since version 2.8.
</p>

<p>
Gnome and XFce desktop environments have been created using the GTK+ library. 
SWT and wxWidgets are well known programming frameworks, that use GTK+. 
Prominent software applications that use GTK+ include Firefox or Inkscape.
</p>

<h2>Compiling GTK+ applications</h2>

<p>
To compile GTK+ applications, we have a handy tool called <b class="keyword">pkg-config</b>.
The pgk-config returns metadata about installed libraries. Simply put, if we 
want to use a specific library, it will provide us necessary dependent libraries and 
include files, that we need. The pkg-config program retrieves information about 
packages from special metadata files. 
</p>

<pre class="code">
 gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`
</pre>

<p>
Here we show, how we can compile a simple program. The source code consists of one file, simple.c. 
</p>

<pre class="code">
$ pkg-config --cflags gtk+-2.0
-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 
-I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 
-I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12  
</pre>

<p>
This list shows all necessary include files for GTK+ programming. 
</p>

<pre class="code">
$ pkg-config --libs gtk+-2.0
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 
-lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr 
-lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0 
-lgmodule-2.0 -ldl -lglib-2.0 
</pre>

<p>
And this list shows the necessary libraries. 
</p>

<h2>Sources</h2>

<ul>
<li><a href="http://www.gtk.org">gtk.org</a></li>
<li><a href="http://www.gtkforums.com">gtkforums.com</a></li>
<li>GTK+ / Gnome application development</li>
</ul>


<hr class="btm">

<p>
This was an introduction to GTK+ library.
</p>

<br>
<div class="center"> 
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
</div>
<br>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified March 30, 2008  <span class="copyright">&copy; 2007 - 2012 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>
